//
//  User.m
//  MovieDate
//
//  Created by 杨运涛 on 16/3/15.
//  Copyright © 2016年 MovieDate. All rights reserved.
//

#import "User.h"

@implementation User
static User *static_default_user;

+ (instancetype)defaultUser
{
    if (!static_default_user) {
        static_default_user = [[User alloc] init];
        static_default_user.uid = @"";
        static_default_user.pStrName = @"";
        static_default_user.pStrNickName = @"";
        static_default_user.userSex = @"";
        
        static_default_user.pStrLongitude = @"0";
        static_default_user.pStrLatitude = @"0";
        static_default_user.pStrLocationAddress = @"";
        static_default_user.zambia = @"0";
        static_default_user.fans = @"0";
        static_default_user.faceScore = @"0";
        static_default_user.signature = @" ";
        static_default_user.newesdAlbumArray = [NSMutableArray array];
        static_default_user.labels = [NSMutableArray array];
    
    }
    return static_default_user;
}

- (NSString *)getCurTime{
    NSDate *currentDate = [NSDate date];//获取当前时间，日期
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"YYYY/MM/dd hh:mm:ss SS"];
    NSString *dateString = [dateFormatter stringFromDate:currentDate];
    return dateString;
}

- (void)setActiveTime:(NSString *)activeTime
{
    _activeTime = activeTime;
    
    NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    
    //创建了两个日期对象
    NSDate *date1 = [dateFormatter dateFromString:activeTime.length>=16?[activeTime substringToIndex:16]:@""];
    NSDate *date=[NSDate date];
    NSString *curdate=[dateFormatter stringFromDate:date];
    NSDate *date2 = [dateFormatter dateFromString:curdate];
    
    //取两个日期对象的时间间隔：
    //这里的NSTimeInterval 并不是对象，是基本型，其实是double类型，是由c定义的:typedef double NSTimeInterval;
    NSTimeInterval time=[date2 timeIntervalSinceDate:date1];
    
    int days=((int)time)/(3600*24);
    int hours=((int)time)%(3600*24)/3600;
    NSString *dateContent = [[NSString alloc] initWithFormat:@"%@%i小时前", days>0?[NSString stringWithFormat:@"%i天", days]:@"", hours>=0?hours:-hours];
    _activeTimeLast = dateContent;
}

@end
